//
//  ScanGoodDetailListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/11/11.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "ScanGoodDetailListCell.h"

@interface ScanGoodDetailListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *numTitleLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UIButton *operationBtn;
@property (nonatomic, strong) UILabel *line;

@end

@implementation ScanGoodDetailListCell

+ (instancetype)ScanGoodDetailListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"ScanGoodDetailListCell";
    ScanGoodDetailListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ScanGoodDetailListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, ScreenW - 30, 77)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
        
        self.numTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20, [FactoryMethod sizeWithText:@"包装编号：" font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(0, 0)].width, 17)];
        self.numTitleLab.textColor = HexColor(0x9C9DB3);
        self.numTitleLab.font = [UIFont systemFontOfSize:14];
        self.numTitleLab.text = @"包装编号：";
        [self.bgView addSubview:self.numTitleLab];
        
        self.numLab = [[UILabel alloc] initWithFrame:CGRectMake(self.numTitleLab.nim_right, self.numTitleLab.nim_top, self.bgView.nim_width - 15 - 92 - 10 - self.numTitleLab.nim_right, self.numTitleLab.nim_height)];
        self.numLab.textColor = HexColor(0x2B2C44);
        self.numLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.numLab];
        
        self.countTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(self.numTitleLab.nim_left, self.numTitleLab.nim_bottom + 3, self.numTitleLab.nim_width, self.numTitleLab.nim_height)];
        self.countTitleLab.textColor = HexColor(0x9C9DB3);
        self.countTitleLab.font = [UIFont systemFontOfSize:14];
        self.countTitleLab.text = @"货物数量：";
        [self.bgView addSubview:self.countTitleLab];
        
        self.countLab = [[UILabel alloc] initWithFrame:CGRectMake(self.countTitleLab.nim_right, self.countTitleLab.nim_top, self.numLab.nim_width, self.countTitleLab.nim_height)];
        self.countLab.textColor = HexColor(0x2B2C44);
        self.countLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countLab];
        
        self.operationBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.numLab.nim_right + 10, (self.bgView.nim_height - 30) * 0.5, 92, 30)];
        self.operationBtn.backgroundColor = HexColorA(0xF35959, 0.1);
        self.operationBtn.layer.masksToBounds = YES;
        self.operationBtn.layer.cornerRadius = 15;
        [self.operationBtn setTitle:@"解除绑定" forState:0];
        [self.operationBtn setTitleColor:HexColor(0xF35959) forState:0];
        self.operationBtn.titleLabel.font = BoldFontOfSize(14);
        [self.operationBtn addTarget:self action:@selector(operationClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.operationBtn];
        
        self.line = [[UILabel alloc] initWithFrame:CGRectMake(15, self.bgView.nim_height - 1, self.bgView.nim_width - 30, 1)];
        self.line.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.line];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)operationClick {
    if (self.jieChuBlock) {
        self.jieChuBlock();
    }
}

-(void)setModel:(ScanGoodDetailModel *)model {
    _model = model;
    self.numLab.text = model.num_sn;
    self.countLab.text = model.num;
    if (model.is_bind == 1) {
        [self.operationBtn setTitle:@"解除绑定" forState:0];
        [self.operationBtn setTitleColor:HexColor(0xF35959) forState:0];
        self.operationBtn.backgroundColor = HexColorA(0xF35959, 0.1);
        self.operationBtn.userInteractionEnabled = YES;
    }else {
        [self.operationBtn setTitle:@"已解绑" forState:0];
        [self.operationBtn setTitleColor:HexColor(0x000000) forState:0];
        self.operationBtn.backgroundColor = HexColor(0xffffff);
        self.operationBtn.userInteractionEnabled = NO;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
